(function() {
	Wallet.widget.AccountRecordPanel = function(el, config) {
		Wallet.lang.applyIf(config, {
			fixedCenter: false,
			modal: false,
			constrainToViewport: true
		});
		
		Wallet.widget.AccountRecordPanel.superclass.constructor.call(this, el, config);
	};
	
	var Lang = YAHOO.lang,
		Panel = YAHOO.widget.Panel,
		AccountRecordPanel = Wallet.widget.AccountRecordPanel,
		AccountRecordDataTable = Wallet.widget.AccountRecordDataTable,
		AccountRecordFormPanel = Wallet.widget.AccountRecordFormPanel;
		
	var DEFAULT_CONFIG = {
		"DATAURI": {
			key: "dataUri", 
			value: null,
            //validator: Lang.isNumber, 
            suppressEvent: true, 
            supercedes: ["iframe"]
		}
	};
	
	Lang.extend(AccountRecordPanel, Panel, {
		init: function(el, userConfig) {
			AccountRecordPanel.superclass.init.call(this, el);
			
			this.beforeInitEvent.fire(AccountRecordPanel);
            
            if (userConfig) {
                this.cfg.applyConfig(userConfig, true);
            }
            
            this.initComponents();
            this.initListener();
            
            this.initEvent.fire(AccountRecordPanel);			
		},
		initDefaultConfig: function() {
			AccountRecordPanel.superclass.initDefaultConfig.call(this);
			
			this.cfg.addProperty(DEFAULT_CONFIG.DATAURI.key, {            
                handler: this.configDataUri,
                value: DEFAULT_CONFIG.DATAURI.value, 
                //validator: DEFAULT_CONFIG.DATAURI.validator, 
                supercedes: DEFAULT_CONFIG.DATAURI.supercedes
            });
		},
		initComponents: function() {
			this.toolbar = Dom.getElementsByClassName("tb", "div", this.body)[0];
			var el = this.toolbar.firstChild;
			
			do {
				var btnEl = el;
				el = el.nextSibling;
				
				if (1 == btnEl.nodeType) {
					if (btnEl.className == "add-btn") {
//						var menu = this._getAddMenu();
							
						new YAHOO.widget.Button(btnEl, {
							type: "push",
							className: "icon-button add-icon",
//							menu: menu,
							onclick: {
								fn: this.onEventAddButtonClick,
								scope: this,
								obj: this
							}
						});	
					} else if (btnEl.className == "del-btn") {
						new YAHOO.widget.Button(btnEl, {
							type: "push",
							className: "icon-button remove-icon"
						});
					} else if (btnEl.className == "dtl-btn") {
						new YAHOO.widget.Button(btnEl, {
							type: "push",
							className: "icon-button view-icon"
						});
					}
				}
			} while (el)
		},
		initListener: function() {
			
		},
		configDataUri: function(type, args, obj) {
			var uri = args[0];
			
			if (uri) {
				this.dataUri = uri;
			}
		},
		load: function(date) {
			this.header.innerHTML = "Account Record - " + date;	
			
			if (!this.dataTable) {
				var month = date.substr(0, 7);
				
				this.dataTable = new AccountRecordDataTable("div-detail-data-table-" + month, {
					dataUri: this.dataUri,
					initialRequest: date
				});
			}
			
			this.dataTable.load(date);
		},
		onEventAddButtonClick: function(evt, data) {
			var panel = this._getAccountRecordFormPanel();
			panel.show();
			Wallet.widget.OverlayManager.bringToTop(panel);
		},
		_getAccountRecordFormPanel: function() {
			if (!this.accountRecordFormPanel) {
				document.body.appendChild(Dom.get("account-record-form-panel"));
				this.accountRecordFormPanel = new AccountRecordFormPanel(
					"account-record-form-panel", {							
				});
				
				this.accountRecordFormPanel.render();
				Wallet.widget.OverlayManager.register(this.accountRecordFormPanel);
			}
			
			return this.accountRecordFormPanel;
		}		
	}); 
}());